/*
 * RFReceiverModule.cpp
 *
 *  Created on: Mar 1, 2012
 *      Author: xum
 */

#include "RFReceiverModule.h"
#include <VirtualWire.h>

uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

RFReceiverModule::RFReceiverModule(unsigned int port, int baudRate) :
		ReceiverModule() {
	vw_set_rx_pin(port);
	vw_setup(baudRate); // Bits per sec
	vw_rx_start(); // Start the receiver PLL running
}

Message RFReceiverModule::receiveMessage() {
	vw_wait_rx();
	buflen = VW_MAX_MESSAGE_LEN;
	while (vw_get_message(buf, &buflen)==0) {
		vw_wait_rx();
	}
	buf[buflen]='0';
	return Message(String((char *) buf).substring(0,buflen));
}
